/**
 * Copyright (c) 2010 CWI Amsterdam and others. All rights reserved.
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    CWI Amsterdam - initial API and implementation
 */
package nl.cwi.arne.generator.tools;

import java.io.File;

import nl.cwi.arne.Network;
import nl.cwi.arne.mcrl2.util.MCRL2Options;
import nl.cwi.arne.mcrl2.util.MCRL2Options.Equivalence;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;

/**
 * @author Christian Krause
 */
public abstract class AbstractGeneratorTool implements IApplication {
	
	// Dummy monitor:
	protected final IProgressMonitor monitor = new NullProgressMonitor();
	
	// mCLR2 dome dir:
	protected File mcrl2Home;
	
	/**
	 * Get mCRL2 options.
	 * @return mCRL2 options.
	 */
	protected MCRL2Options getMCRL2Options() {
		MCRL2Options options = new MCRL2Options();
		options.setEquivalence(Equivalence.BISIM);
		options.setLpssumelm(true);
		options.setLtsconvert(true);
		options.setLtsinfo(true);
		return options;
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.eclipse.equinox.app.IApplication#stop()
	 */
	@Override
	public void stop() {
		monitor.setCanceled(true);
	}
	
	protected Network loadNetwork(IApplicationContext context) throws Exception {
		String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
		ResourceSet resourceSet = new ResourceSetImpl();
		String path = args[0];
		System.out.println("Loading " + path + "...");
		Resource resource = resourceSet.getResource(URI.createFileURI(path), true);
		return (Network) resource.getContents().get(0);
	}

}
